﻿using StockHelper.Scripts;
using StockHelper.Scripts.Stock;
using StockHelper.Scripts.Types;
using System;
using System.Collections;
using System.Windows.Forms;

namespace StockHelper
{
    public partial class AddStockVoice : Form
    {
        Hashtable data;
        VoiceForm form;

        public AddStockVoice(VoiceForm f,Hashtable t)
        {
            InitializeComponent();
            data = t;
            form = f;
            
            foreach (string key in StockCtrl.stockData.Keys)
                this.VoiceList.Items.Add(StockCtrl.GetData(key, Param.名称));

            if(this.VoiceList.Items.Count>0)
            this.VoiceList.SelectedIndex = 0;
        }

        private void Add_Btn_Click(object sender, EventArgs e)
        {
            foreach (string key in StockCtrl.stockData.Keys) {
                if (this.VoiceList.Text == StockCtrl.GetData(key, Param.名称).ToString()) {

                    data["url"] = key;
                    Config.Get("voicePlay", new ArrayList()).Add(data);
                    Config.Save();
                    VoicePlay.e.Init();

                    form.Close();
                    form.Dispose();
                    this.Close();
                    this.Dispose();
                    return;
                }
            }
            MessageBox.Show("系统异常");
        }
    }
}
